package cn.edu.lcu.cs.javaweb.entity;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

import org.apache.commons.dbutils.annotations.Column;

public class User {
	private Long id;
	private String username;
	private LocalDate birthdate;
	private String password;
	private String email;
	private String mobile;
	private String role; // 角色，admin common
	private boolean valid; // 用户是否有效
	private String realName;

	// private int age; // 年龄，Field，不是Property
	// 对于一个JavaBean，将getter setter方法的前缀get set去掉，剩下的名称首字母小写，就是Property

	public long getAge() {
		long age = ChronoUnit.YEARS.between(birthdate, LocalDate.now());
		return age;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public LocalDate getBirthdate() {
		return birthdate;
	}

	public void setBirthdate(LocalDate birthdate) {
		this.birthdate = birthdate;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public User() {
		super();
		// TODO Auto-generated constructor stub
	}

	public User(Long id, String username, LocalDate birthdate, String password, String email, String mobile,
			String role) {
		super();
		this.id = id;
		this.username = username;
		this.birthdate = birthdate;
		this.password = password;
		this.email = email;
		this.mobile = mobile;
		this.role = role;
	}

	/**
	 * 布尔类型字段的getter方法前缀可以是is，也可以是get，如果都存在就以is为准
	 * 
	 * @return
	 */
	public boolean isValid() {
		System.out.println("isValid()");
		return valid;
	}

	/**
	 * 布尔类型字段的getter方法前缀可以是is，也可以是get，如果都存在就以is为准
	 * 
	 * @return
	 */
	public boolean getValid() {
		System.out.println("getValid()");
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

}
